package com.jimmy.ioc.annotation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @version 1.0
 * @ ClassName BookService
 * <p> TODO
 * @ author JIMMY
 * @ Date 2020/10/23 0023 下午 9:36
 */
@Service
//@Scope("prototype") //设置作用域
public class BookService {
    @Autowired
    @Qualifier("bookDao") //指定名字如果是接口引用实现类可能有多个
//   @Resource("bookDao") 用来取代 autowired qualifier组合
    private BookDao bookDao;

    @Autowired
    @Value("jimmy")
    private String msg;
    public void save(){
        System.out.println(msg);
        bookDao.save();
    }
//    声明为初始化方法
    @PostConstruct
    public void init(){
        System.out.println("bookService init");
    }
    @PreDestroy
    public void destroy(){
        System.out.println("bookService destroy");
    }
}
